package com.shengsheng.expschedule.service.ucenter.controller.api;


import com.shengsheng.expschedule.base.result.R;
import com.shengsheng.expschedule.service.ucenter.entity.Vo.LoginVo;
import com.shengsheng.expschedule.service.ucenter.entity.Vo.RegisterVo;
import com.shengsheng.expschedule.service.ucenter.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author yuan
 * @since 2021-11-04
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/api/ucenter/teacher")
@RefreshScope
public class ApiTeacherController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public R login(@ApiParam(value = "登录表单对象",required = true)
                   @RequestBody LoginVo loginVo) {
        return R.ok()
                .data("token", teacherService.login(loginVo))
                .message("登陆成功");
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public R register(@ApiParam(value = "注册表单对象",required = true)
                      @RequestBody RegisterVo registerVo) {
        if (teacherService.register(registerVo)) return R.ok().message("注册成功");
        return R.error().message("注册失败");
    }
}

